<?php
include_once 'Panel/pnlHeader.php';
include_once 'prepend.inc.php';

class AssetLog extends QForm
{
	protected $txtSearchTerm;
	protected $btnSearch;
	protected $dtrAssetLog;
	protected $pnlHeader;
	
	protected function Form_Run()
	{
		QApplication::$LoadedPage = 'Asset Log';
		QApplication::CheckRemoteAdmin();
	}
	
	protected function Form_Create()
	{
		$this->txtSearchTerm_Create();
		$this->btnSearch_Create();
		$this->dtrAssetLog_Create();
		$this->pnlHeader_Create();
	}
	
	protected function txtSearchTerm_Create()
	{
		$this->txtSearchTerm = new QTextBox($this);
	}
	
	protected function btnSearch_Create()
	{
		$this->btnSearch = new QButton($this);
		$this->btnSearch->Text = 'Search';
		$this->btnSearch->AddAction(new QClickEvent(),new QAjaxAction('btnSearch_Click'));
	}
	
	protected function dtrAssetLog_Create()
	{
		$this->dtrAssetLog = new QDataRepeater($this);
		$this->dtrAssetLog->Paginator = new QPaginator($this);
		$this->dtrAssetLog->ItemsPerPage = 10;
		$this->dtrAssetLog->UseAjax = false;
		$this->dtrAssetLog->Template = 'assetlogresults.tpl.php';
		$this->dtrAssetLog->SetDataBinder('dtrAssetLog_Bind');
	}
	
	protected function btnSearch_Click()
	{
		$this->dtrAssetLog_Bind();
	}
	
	protected function dtrAssetLog_Bind()
	{
		$result = $this->GetAssetLog();
		$this->dtrAssetLog->TotalItemCount = sizeof($result);
		$this->dtrAssetLog->DataSource = $result;
	}
	
	protected function GetAssetLog()
	{
		$objClauses = array();
		array_push($objClauses, QQ::OrderBy(QQN::Assetsauditlog()->RealReturnDate));
		if($this->txtSearchTerm->Text == "")
		{
			$condition = QQ::Equal(QQN::Assetsauditlog()->Owner,$_SESSION['User']);
			$myassets = Assetsauditlog::QueryArray($condition,$objClauses);
		}
		else
		{
			$objCondition = QQ::AndCondition(
														QQ::OrCondition(
																	QQ::Like(QQN::Assetsauditlog()->Asin,'%'. $this->txtSearchTerm->Text . '%'),
																	QQ::Like(QQN::Assetsauditlog()->Email,'%'. $this->txtSearchTerm->Text . '%'),
																	QQ::Like(QQN::Assetsauditlog()->Title,'%'. $this->txtSearchTerm->Text . '%'),
																	QQ::Like(QQN::Assetsauditlog()->FullName,'%'. $this->txtSearchTerm->Text . '%')
																),
																QQ::Equal(QQN::Assetsauditlog()->Owner,$_SESSION['User'])
																); 
			$objDbResult = Assetsauditlog::QueryArray($objCondition, $objClauses);
			$myassets = $objDbResult;
			
		}
		
		return $myassets;
	}

	protected function pnlHeader_Create()
	{
		$this->pnlHeader = new pnlHeader($this, 'CloseEditPane');
	}
}

AssetLog::Run('AssetLog');
?>